#pragma once

#include "LinkEndCreationData.h"

#include "InputPin.h"

namespace uml {

const bool LinkEndCreationData::isReplaceAll_default_ = false;
LinkEndCreationData::LinkEndCreationData(const QString& umlType)
    : LinkEndData(umlType) {}

void LinkEndCreationData::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    LinkEndData::fromJson(json, errorList);
    insertAt_ = JsonSerializable::create<InputPin>(json.value("insertAt"), errorList);

    isReplaceAll_ = json.value("isReplaceAll").toBool(isReplaceAll_default_);
}

void LinkEndCreationData::toJson(QJsonObject& json) {
    LinkEndData::toJson(json);
    if (insertAt_) {
        QJsonObject insertAt_json;
        insertAt_->toJson(insertAt_json);
        json.insert("insertAt", insertAt_json);
    }
    if (isReplaceAll_ != isReplaceAll_default_) {
        json.insert("isReplaceAll", isReplaceAll_);
    }
}

/// <summary>
/// allPins
    /// Adds the insertAt InputPin (if any) to the set of all Pins.
/// </summary>
    /// <code>
    /// result = (self.LinkEndData::allPins()->including(insertAt))
    /// </code>
shared_ptr<vector<InputPin>> LinkEndCreationData::allPins() const
{
    return nullptr;
}

/// <summary>
/// insertAt getter
/// For ordered Association ends, the InputPin that provides the position where the
/// new link should be inserted or where an existing link should be moved to. The
/// type of the insertAt InputPin is UnlimitedNatural, but the input cannot be zero.
/// It is omitted for Association ends that are not ordered.
/// </summary>
shared_ptr<InputPin> LinkEndCreationData::insertAt() const {
    return insertAt_;
}

/// <summary>
/// insertAt setter
/// For ordered Association ends, the InputPin that provides the position where the
/// new link should be inserted or where an existing link should be moved to. The
/// type of the insertAt InputPin is UnlimitedNatural, but the input cannot be zero.
/// It is omitted for Association ends that are not ordered.
/// </summary>
void LinkEndCreationData::setInsertAt(shared_ptr<InputPin> value) {
    insertAt_ = value;
}

/// <summary>
/// isReplaceAll getter
/// Specifies whether the existing links emanating from the object on this end
/// should be destroyed before creating a new link.
/// </summary>
bool LinkEndCreationData::isReplaceAll() const {
    return isReplaceAll_;
}

/// <summary>
/// isReplaceAll setter
/// Specifies whether the existing links emanating from the object on this end
/// should be destroyed before creating a new link.
/// </summary>
void LinkEndCreationData::setIsReplaceAll(bool value) {
    isReplaceAll_ = value;
}

} // namespace uml
